/*
 * @brief 这里是处理服务端的session，这里需要创建线程
 * @auther aolei1024@gmail.com
 * @date 2019-08-27
 */
#ifndef _SERVERSESSION_H_
#define _SERVERSESSION_H_

#include "UdpConnect.h"
#include "KcpConnect.h"
#include <memory>
#include <unordered_map>
#include <list>
#include <string>
#include <thread>
#include<mutex>
#include <set>
#include <condition_variable>

struct messages
{

};

struct Accept
{
    std::shared_ptr<KcpConnect> conn = nullptr;
};
class Listener 
{
    public:
        Listener(std::string ip,int port);
        ~Listener();
        int bind();
        std::shared_ptr<KcpConnect> accept();
        void Logic(char* data,int len,struct sockaddr_in addrs);
        //可读事件
        void EpollWait(std::set<uint32_t>& v);
    public:
        static void MainFun(Listener* l);
    private:
        void NotifAll();
    private:
        std::unique_ptr<UdpConnect> conn = nullptr;
        int fd = -1;
        std::unordered_map<uint32_t,std::shared_ptr<UdpConnect>> list;//对应的各个链接的消息队列
        std::list<Accept> acclist;
        std::set<uint32_t> change;
        std::string addr;
        int port = -1;
        std::thread t1;
        std::condition_variable cv;
        std::mutex lock;
        int count = 0;

        int beginSessid = 1;
};





#endif //_SERVERSESSION_H_
